package com.zcmob.web.admanagement.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

public class FileUtils {
    
    public static boolean copyFile(String oldPath, String newPath, String newFileName) throws IOException {

        int byteread = 0;
        File oldfile = new File(oldPath);
        if (oldfile.exists()) {
            InputStream inStream;
            FileOutputStream fs;

            File newfile = new File(newPath);
            if (!newfile.exists()) {
                newfile.mkdirs();
            }

            fs = new FileOutputStream(newPath + newFileName);

            inStream = new FileInputStream(oldPath);

            byte[] buffer = new byte[1444];

            while ((byteread = inStream.read(buffer)) != -1) {

                fs.write(buffer, 0, byteread);
            }
            inStream.close();

            return true;
        } else
            return false;
    }
    
    public static String getImageResolution(String imageFilepath){
        String result = null;
        File file = new File(imageFilepath);  
        file.exists();
        BufferedImage bi = null;
        
        try {  
            bi = ImageIO.read(file);  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {
            bi.flush();
        }
        if (bi != null) {
            result = bi.getWidth() + "*" + bi.getHeight();
        }
        
        return result;
    }
}
